<template>
  <div class="app-container">
    <div class="search-form">
      <el-form :model="params" inline label-width="90px" size="small">
        <el-form-item label="任务状态">
          <el-select v-model="params.status" placeholder="请选择" clearable style="width: 240px">
            <el-option :value="1" label="待接收"></el-option>
            <el-option :value="2" label="进行中"></el-option>
            <el-option :value="3" label="已完成"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="设计师">
          <el-input v-model="params.designerId" placeholder="请输入" clearable style="width: 240px"></el-input>
        </el-form-item>
        <el-form-item label="最小年龄">
          <el-input v-model.number="params.minAge" clearable style="width: 240px"></el-input>
        </el-form-item>
        <el-form-item label="最大年龄">
          <el-input v-model.number="params.maxAge" clearable style="width: 240px"></el-input>
        </el-form-item>
        <el-form-item label="服装分类">
          <el-select v-model="params.gender" placeholder="请选择" clearable style="width: 240px">
            <el-option :value="1" label="男装"></el-option>
            <el-option :value="2" label="女装"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="服装类型">
          <el-select v-model="params.type" placeholder="请选择" clearable style="width: 240px">
            <el-option :value="0" label="内衬"></el-option>
            <el-option :value="1" label="上衣"></el-option>
            <el-option :value="2" label="外套"></el-option>
            <el-option :value="3" label="裤装"></el-option>
            <el-option :value="4" label="裙装"></el-option>
            <el-option :value="5" label="套装"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="成本">
          <el-input v-model.number="params.cost" style="width: 240px"></el-input>
        </el-form-item>
        <el-form-item label="设计师等级">
          <el-input v-model.number="params.level" style="width: 240px"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-row :gutter="20">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-plus" @click="handleAddTask">新增任务</el-button>
      </el-col>
    </el-row>
    <div class="table">
      <el-table :data="tableData" stripe>
        <el-table-column type="expand">
          <template slot-scope="props">
            <el-table :data="props.row.requires" stripe>
              <el-table-column label="服装分类" align="center" prop="gender">
                <template slot-scope="scope">
                  {{ scope.row.gender === 1 ? "男装" : "女装" }}
                </template>
              </el-table-column>
              <el-table-column label="服装类型" align="center" prop="types">
                <template slot-scope="scope">
                  <span v-if="scope.row.types === 0">内衬</span>
                  <span v-if="scope.row.types === 1">上衣</span>
                  <span v-if="scope.row.types === 2">外套</span>
                  <span v-if="scope.row.types === 3">裤装</span>
                  <span v-if="scope.row.types === 4">裙装</span>
                  <span v-if="scope.row.types === 5">套装</span>
                </template>
              </el-table-column>
              <el-table-column label="最小年龄" align="center" prop="minAge"></el-table-column>
              <el-table-column label="最大年龄" align="center" prop="maxAge"></el-table-column>
              <el-table-column label="服装风格" align="center" prop="style"></el-table-column>
              <el-table-column label="面料要求" align="center" prop="material"></el-table-column>
              <el-table-column label="最大成本" align="center" prop="cost"></el-table-column>
              <el-table-column label="设计师等级" align="center" prop="level"></el-table-column>
              <el-table-column label="具体需求" align="center" prop="require"></el-table-column>
              <el-table-column label="功能描述" align="center" prop="functionality"></el-table-column>
            </el-table>
          </template>
        </el-table-column>
        <el-table-column label="任务ID" align="center" width="80" prop="usTask.orderId"></el-table-column>
        <el-table-column label="任务状态" align="center" prop="usTask.status"></el-table-column>
        <el-table-column label="任务创建时间" align="center" prop="usTask.createTime"></el-table-column>
        <el-table-column label="任务更新时间" align="center" prop="usTask.updateTime"></el-table-column>
        <el-table-column label="操作" align="center" width="100">
          <template slot-scope="scope">
            <el-tooltip content="查看" placement="top">
              <el-button type="text" icon="el-icon-view" @click="handleShowDetail(scope.row)"></el-button>
            </el-tooltip>
            <el-tooltip content="编辑" placement="top">
              <el-button type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"></el-button>
            </el-tooltip>
            <el-tooltip content="删除" placement="top">
              <el-button type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          class="pageList"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="params.size"
          :current-page.sync="params.startPage"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          style="text-align: center; margin: 30px 0"
      ></el-pagination>
    </div>
    <TaskDialog ref="TaskDialog" :task-data="currentRow" :is-edit="isEdit" @getList="getList"></TaskDialog>
  </div>
</template>

<script>
import {deleteTask, getTaskList} from "@/api/consultant/task";
import TaskDialog from "@/components/TaskDialog"
export default {
  name: "taskList",
  components: { TaskDialog },
  data() {
    return {
      params: {
        startPage: 1,
        size: 10,
        status: null,
        designerId: null,
        minAge: null,
        maxAge: null,
        gender: null,
        type: null,
        cost: null,
        level: null
      },
      tableData: [],
      total: 0,
      currentRow: "",
      isEdit: false
    }
  },
  mounted() {
    this.getList();
  },
  methods: {
    getList() {
      getTaskList(this.params)
          .then((res) => {
            this.tableData = res;
            this.total = res.length;
          })
          .catch((err) => {});
    },
    handleQuery() {
      this.params.startPage = 1;
      this.getList();
    },
    handleSizeChange(val) {
      this.params.size = val;
      this.params.startPage = 1;
      this.getList();
    },
    handleCurrentChange(val) {
      this.params.startPage = val;
      this.getList();
    },
    handleAddTask() {
      this.isEdit = false;
      this.currentRow = ""
      this.$refs.TaskDialog.open()
    },
    handleShowDetail(row) {
      this.isEdit = false;
      this.currentRow = JSON.parse(JSON.stringify(row));
      setTimeout(() => {
        this.$refs.TaskDialog.open();
      }, 0);
    },
    handleUpdate(row) {
      this.isEdit = true;
      this.currentRow = JSON.parse(JSON.stringify(row));
      setTimeout(() => {
        this.$refs.TaskDialog.open();
      }, 0);
    },
    handleDelete(row) {
      this.$confirm("确认要删除该条数据吗?", "提示", {
        type: "warning"
      }).then(() => {
        deleteTask(row.usTask.id).then(res => {
          this.$message.success("删除成功");
          this.getList();
        })
      }).catch(() => {})
    }
  },
}
</script>

<style scoped>

</style>